<template>
	<view>
		<!-- v-if="JSON.stringify(address == '{}')" -->
		<view class="address-show-box" v-if="JSON.stringify(address) == '{}'">
			<button type="primary" @click="getAddress">请选择收货地址</button>
		</view>
		<view class="address-info-box" v-else>
			<!-- xxx -->
			<view class="row1">
				<view class="row1-left">
					<view class="uesrname">
						收货人：<text>{{address.userName}}</text>
					</view>
				</view>
				<view class="row1-right">
					<view class="phone">
						电话：<text>{{address.telNumber}}</text>
					</view>
					<uni-icons type="right" size="30"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="row2-address">
					收货地址：<text>{{addressStr}}</text>
				</view>
			</view>
		</view>
		<image src="/static/cart_border@2x.png" class="address-border-img"></image>
	</view>
</template>

<script>
	// import {mapMutations,mapState} from 'vuex';
	import {mapMutations,mapState} from 'vuex';
	export default {
		name:"my-address",
		data() {
			return {
				// address:{}
			};
		},
		// created() {
		// 	console.log(this.$store);
		// },
		created() {
			console.log(this.$store);
		},
		computed:{
			// ...mapState('user_m',['address']),
			...mapState('user_m',['address']),
			addressStr(){
				return this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo
			}
		},
		methods:{
			// ...mapMutations('user_m','[updateAddress]'),
			...mapMutations('user_m',['updateAddress']),
			async getAddress(){
				const [err,succ] = await uni.chooseAddress().catch(err=>err);
				// console.log(result);
				console.log(succ);
				if(err === null && succ.errMsg == 'chooseAddress:ok'){
					// this.address = succ;
					this.updateAddress(succ);
				}else{
					return uni.$showMsg()
				}
			}
		}
	}
</script>

<style lang="scss">
.address-show-box{
	height: 50px;
	display: flex;
	justify-content: center;
	align-items: center;
}
	.address-info-box {
		.row1 {
			height: 40px;
			display: flex;
			justify-content: space-between;
			.row1-right {
				display: flex;
				flex-wrap: nowrap;
			}
		}
		.row2 {
			height: 40px;
		}
	}
.address-border-img {
	height: 5px;
	width: 100%;
	display: block;
	
}
</style>
